﻿using Batman.Cms.Core.Const;
using System.Security.Claims;

namespace Batman.Cms.Core.Extensions
{
    public static class ClaimsPrincipalExtension
    {
        /// <summary>
        /// 获取当前用户的用户Id
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static string GetUserId(this ClaimsPrincipal user)
        {
            var nameIdentifier = user.FindFirst(ClaimTypes.NameIdentifier);
            if (nameIdentifier == null) return null;

            return nameIdentifier.Value;
        }

        /// <summary>
        /// 获取当前用户的用户显示名称
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static string GetUserDisplayName(this ClaimsPrincipal user)
        {
            var name = user.FindFirst(BatmanCliamTypes.DisplayName);
            if (name == null) return null;

            return name.Value;
        }
    }
}
